package com.tofacebook.service.impl;

import com.tofacebook.mapper.EmpMapper;
import com.tofacebook.model.Emp;
import com.tofacebook.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    public Emp getEmpByEmpId(long empId) {
        //log.info("操作之前，empId的值为：{}",empId);
        Emp empByEmpId = empMapper.getEmpByEmpId(empId);
        //log.info("操作之后，Emp对象的值为：{}",empByEmpId);
        return empByEmpId;
    }

    public int saveEmp(Emp emp) {
       // log.info("操作之前，传递的值为：{}", emp);
        int num = 0;
        if (empMapper.getEmpByEmpName(emp.getEmpName()) <= 0) {
            num = empMapper.saveEmp(emp);
            if (num > 0) {
                log.info("保存员工信息之后,成功的记录为：{}", num);
            }
        }else{
            log.info("保存信息失败：{} 已经存在了", emp.getEmpName());
        }
        //log.info("操作之后：{}", num);
        return num;
    }
}
